package com.samphanie.auiu.admin.controller;

import com.samphanie.auiu.admin.service.IAdminUserService;
import com.samphanie.auiu.common.dto.AdminLoginDto;
import com.samphanie.auiu.common.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author ZSY
 * @email 1451691457@qq.com
 */
@Api(tags = "授权认证服务中心")
@RestController
@RequestMapping("/admin")
@RequiredArgsConstructor
public class AuthorizeController {

    private final IAdminUserService userService;

    @ApiOperation("获取图片验证码")
    @ApiImplicitParam(name = "deviceId", value = "唯一标识：客户端ID+用户设备码", paramType = "header", dataTypeClass = String.class, required = true)
    @GetMapping("/code/image")
    public void getImageCode(HttpServletResponse servletResponse) {
        userService.getImageCode(servletResponse);
    }

    @ApiOperation("用户登录")
    @ApiImplicitParam(name = "deviceId", value = "唯一标识：客户端ID+用户设备码", paramType = "header", dataTypeClass = String.class, required = true)
    @PostMapping("/login")
    public ApiResponse<?> login(@RequestBody AdminLoginDto loginDto) {
        return userService.adminLogin(loginDto);
    }

    @ApiOperation("用户详情")
    @GetMapping("/user/info")
    public ApiResponse<?> getCurrentAdminUser() {
        return userService.getCurrentAdminUser();
    }

}
